<template lang="jade">
div
  //- List
  h-loader-full(url='loader')
    h-data-lister
    m-title(icon='add',name='培训课程列表')
      select(v-model='p.type')
        option(value='', selected) 请选择类别
        option(v-for='(n,i) in type', :value='i') {{n}}
      input(type='text', placeholder='请填写课程名称', v-model='p.name',style='width:100px;')
      button(@click='filter(p)') 过滤
    table.list
      ml-header(data='ID:3, 课程名称:5, 开课时间:5, 报名结束时间:5,课程关键字:5, 课程类型:5, 上课地址:5, 联系电话:5, 操作:5')
      tr(v-for='(v, i) in list')
        td {{ v.id }}
        td: input(type='text',v-model='v.name')
        td  {{new Date(v.class_starttime*1000).format('yyyy-MM-dd hh:mm:ss')}}
        td  {{new Date(v.apply_endtime*1000).format('yyyy-MM-dd hh:mm:ss')}}
        td: input(type='text',v-model='v.keyword')
        td  {{type[v.type]}}
        td: input(type='text',v-model='v.address')
        td: input(type='text',v-model='v.mobile')
        td
          a(href='javascript:void(0)',class='update',:data-index='i') 更新
          a(:href="'edit.html?id=' + v.id + '&type=' + v.type") 编辑
          // a(href='javascript:void(0)',class='remove',:data-index='i') 删除
    .command
      button(id='update-all') 全部更新
      .page
        button(v-show='page>1', @click="pagego('last')") 上一页
        button {{page}}
        button(@click="pagego('next')") 下一页
</template>
<script>
export default {
	data () {
		return {
      loader:{
        list:'cultivate/list'
      },
      list : [],
      type:['学校','瑞安机电培训','职称考试','企业培训'],
      p:{
        type:'',
        name:''
      },
      page:1,
      url:{
        update:'cultivate/uprow',
        remove:'cultivate/delete'
      }
		}
	},
	methods: {
    loadAfter(res){
			this.list = res.list[0]
			console.log(this.list)
		},
    filter(p){
			this.$ajax.get('cultivate/list?name=' + this.p.name + '&type=' + this.p.type, (res) => {
				this.list = res.data[0]
				this.page = 1
			}, (res) => {
				this.error(res.message)
			})
		},
    pagego (type) {
      this.page = type == 'last' ? this.page - 1 : this.page + 1
      this.$ajax.get('cultivate/list?name=' + this.p.name + '&type=' + this.p.type + '&page=' + this.page, (res) => {
        this.list = res.data[0]
      }, (res) => {
        this.error(res.message)
      })
    },
	}
}
</script>
<style lang="less" scoped>
@import "../../../plugin/style/mixin";
	input[type='text']{ .w(90%);}
  .page{ float:right; }
		.page a{background: #4db3ff; color: #fff; padding:3px 10px; border-radius:4px; cursor:pointer;}
		.page b{margin:0 10px;}
</style>